import { 
  CONFIRM_USER_REQUEST, 
  CONFIRM_USER_FAILURE, 
  CONFIRM_USER_SUCCESS,
  RESET_USER_REQUEST, 
  RESET_USER_FAILURE, 
  RESET_USER_SUCCESS,
  GET_CODE_REQUEST, 
  GET_CODE_FAILURE, 
  GET_CODE_SUCCESS, 
  GET_CODE_OVER_TIME, 
  CLEAR_ERROR
} from '../constants';

const initialState = {
  isGetCoding: false,
  isGetCode: false,
  isConfirming: false,
  isConfirmed: false,
  isReseting: false,
  isReseted: false,
  error: null
};

function func(state = initialState, action) {
  switch (action.type) {
    case CONFIRM_USER_REQUEST:
      return Object.assign({}, state, {
        isGetCoding: false,
    	  isGetCode: false,
    	  isConfirming: true,
    	  isConfirmed: false,
    	  error: null
      });
    case CONFIRM_USER_FAILURE:
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: false,
        isConfirming: false,
        isConfirmed: false,
        error: action.payload
      });
    case CONFIRM_USER_SUCCESS:
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: false,
        isConfirming: false,
        isConfirmed: true,
        error: null
      });
    case RESET_USER_REQUEST:
      return Object.assign({}, state, {
        isReseting: true,
        isReseted: false,
        error: null
      });
    case RESET_USER_FAILURE:
      return Object.assign({}, state, {
        isReseting: false,
        isReseted: false,
        error: action.payload
      });
    case RESET_USER_SUCCESS:
      return Object.assign({}, state, {
        isReseting: false,
        isReseted: true,
        error: null
      });
    case GET_CODE_REQUEST:
      return Object.assign({}, state, {
        isGetCoding: true,
        isGetCode: false,
        isConfirming: false,
        isConfirmed: false,
        error: null
      });
    case GET_CODE_FAILURE:
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: false,
        isConfirming: false,
        isConfirmed: false,
        error: action.payload
      });
    case GET_CODE_SUCCESS:
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: true,
        isConfirming: false,
        isConfirmed: false,
        error: null
      });
    case GET_CODE_OVER_TIME:
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: false,
        error: null
      });
    case CLEAR_ERROR:
      return Object.assign({}, state, {
        error: null
      });
    case 'CLEAR':
      return Object.assign({}, state, {
        isGetCoding: false,
        isGetCode: false,
        isConfirming: false,
        isConfirmed: false,
        isReseting: false,
        isReseted: false,
        error: null
      });
    default:
      return state
  }
};

export default func;